import React,{useRef,useState,useEffect} from "react"


const Test = () => {
    const [arr, setArr] = useState([0])
    const ref = useRef(arr)
    useEffect(() => {
        console.log(arr)
    }, [arr])
    const handle = (val) => {
        ref.current = val
        setArr(val)
    }
    const getArr = () => {
    return ref.current

    }
    const handleClick = () => {
        Promise.resolve().then(() => {
            handle([...getArr(), 1])
        }).then(() => {
            handle([...getArr(), 22])
        })
    }
    return (
        <div>
            <button onClick={handleClick}>change</button>
        </div>
    )
}

export default Test